import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Login from "../components/Login.vue"
import EventsView2 from "../views/EventsView2.vue"
import KEsView from "../views/KEsView.vue"
import MapsView from "../views/MapsView.vue"
import ImagesView from "../views/ImagesView.vue"
import PdfsView from "../views/PdfsView.vue"
import TimesView from "../views/TimesView.vue"
import AddressesView from "../views/AddressesView.vue"
import PeoplesView from "../views/PeoplesView.vue"

Vue.use(VueRouter)

const routes = [
  { path: '/',redirect: "/login"},
  { path: '/home',
    name: 'home',
    component: HomeView,  
    redirect:"/events2", // 先把HomeView加载进来，在到HomeView组件的<router-view>去显示 WelcomeView
    children:[
      // { path: '/events', component: EventsView, name: "event"},
      // { path: '/eventDetail', component: EventDetailView, name: "eventDetail"},
      { path: '/events2', component: EventsView2, name: "event2"},
      { path: '/knowledgeElements', component: KEsView, name: "knowledgeElements"},
      { path: '/maps', component: MapsView, name: "maps"},
      { path: '/images', component: ImagesView, name: "images"},
      { path: '/pdfs', component: PdfsView, name: "pdfs"},
      { path: '/times', component: TimesView, name: "times"},
      { path: '/addresses', component: AddressesView, name: "addresses"},
      { path: '/peoples', component: PeoplesView, name: "peoples"}
    ]
  },
  { path: '/login', name: 'login', component: Login }

    // { path: '/about', name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // },
]

const router = new VueRouter({
  routes
})
// 挂载路由导航守卫
router.beforeEach((to,from,next)=>{
  // next()
  if(to.path === '/login' || to.path === "/") return next();
  const tokenStr = window.sessionStorage.getItem("token");
  if (!tokenStr) return next("/login");
  next();
});

export default router
